package com.test.jpa.spring.dao;

import com.test.jpa.spring.entities.Person;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/10/23 18:02
 */
@Repository
public class PersonDao {
    /**
     * 如何获取到和当前事务关联的EntityManager对象呢？
     * 通过@PersistenceContext标记成员变量
     */
    @PersistenceContext
    private EntityManager entityManager;

    public void save(Person person) {
        entityManager.persist(person);
    }
}
